package Board;

import java.awt.Color;
import java.awt.Font;

import javax.swing.*;
import javax.swing.border.BevelBorder;

import MainClass.Game;

public class BoardGuiScreen extends JPanel  
{
	private static final long serialVersionUID = 1L;
	private JTextField txtLife;
	private JTextField textField[][];
	private JTextField txtScore;
	private JTextField txtProgress;
	private JTextField txtLevel;
	private JTextField txtNextMonsterIn;
	private JTextField txtNextGiftIn;
	public JProgressBar progressBar ;
	private Game game;
	
	private  Integer Board_row,Board_col;
	private  Integer Box_width,Box_height;

	
	public BoardGuiScreen(int life,int level,int score,int row,int col)
	{
		
		Board_row = row;
		Board_col = col;
		game = Game.GameBuilder();
		initialize();
		SetScreenLife(life);
		SetScreenProgrees(0);
		SetScreenScore(score);
		SetScreenLevel(level);
	}
		
	/**
	 * Initialize the contents of the this.
	 */
	private void initialize() 
	{
		//Board_row = new Integer(20);
		//Board_col = new Integer(45);
		
		Box_width = new Integer(13);
		Box_height = new Integer(13);
		
		
		
		this.setBackground(new Color(255, 255, 255));
		this.setBounds(0, 0, 934, 562);
		this.setLayout(null);
		
		txtLife = new JTextField();
		txtLife.setBackground(new Color(255, 255, 255));
		txtLife.setEditable(false);
		txtLife.setColumns(10);
		txtLife.setFont(new Font("Arial", Font.BOLD, 20));
		txtLife.setText("Life     X     "+game.getLife());
		txtLife.setBounds(10, 11, 146, 34);
		this.add(txtLife);
		
		JPanel panel = new JPanel();
		panel.setBounds(10,56, Board_col*Box_width,Board_row*Box_height);
		this.add(panel);
		panel.setLayout(null);
		
		txtScore = new JTextField();
		txtScore.setBackground(new Color(255, 255, 255));
		txtScore.setBorder(null);
		txtScore.setFont(new Font("Arial", Font.BOLD, 20));
		txtScore.setText("Score:   1000");
		txtScore.setColumns(10);
		txtScore.setBounds(242, 11, 170, 34);
		this.add(txtScore);
		
		txtProgress = new JTextField();
		txtProgress.setBorder(null);
		txtProgress.setFont(new Font("Arial", Font.BOLD, 20));
		txtProgress.setText("Progress: 20 %");
		txtProgress.setColumns(10);
		txtProgress.setBounds(740, 11, 170, 34);
		this.add(txtProgress);
		
		txtNextMonsterIn = new JTextField();
		txtNextMonsterIn.setBorder(null);
		txtNextMonsterIn.setFont(new Font("Arial", Font.BOLD, 20));
		txtNextMonsterIn.setText("Next Monster in : 00:15");
		txtNextMonsterIn.setColumns(10);
		txtNextMonsterIn.setBounds(10, 468, 315, 45);
		this.add(txtNextMonsterIn);
		
		txtNextGiftIn = new JTextField();
		txtNextGiftIn.setBorder(null);
		txtNextGiftIn.setFont(new Font("Arial", Font.BOLD, 20));
		txtNextGiftIn.setText("Next Gift in: 00:12");
		txtNextGiftIn.setColumns(10);
		txtNextGiftIn.setBounds(414, 468, 194, 45);
		this.add(txtNextGiftIn);
		
		progressBar = new JProgressBar();
		progressBar.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		progressBar.setForeground(new Color(153, 102, 204));
		progressBar.setValue(100);
		progressBar.setBounds(618, 467, 290, 46);
		this.add(progressBar);
		progressBar.setVisible(false);
		
		txtLevel = new JTextField();
		txtLevel.setText("Level: 1");
		txtLevel.setFont(new Font("Arial", Font.BOLD, 20));
		txtLevel.setColumns(10);
		txtLevel.setBorder(null);
		txtLevel.setBackground(Color.WHITE);
		txtLevel.setBounds(509, 11, 170, 34);
		this.add(txtLevel);
		
		
		
		textField = new JTextField[Board_row][Board_col];
		for(int i=0;i<Board_row;i++)
		{
			for(int j=0;j<Board_col;j++)
			{
				textField[i][j] =new JTextField();
				textField[i][j].setBounds(j*Box_width,i*Box_height, Box_width, Box_height);
				textField[i][j].setEditable(false);
				textField[i][j].setBackground(Color.WHITE);
				// if Border of game
				if(i==0 || i==1 || i==Board_row-1 || i==Board_row-2)
				{
					textField[i][j].setBackground(Color.GREEN);
				}
				if(j==0 || j==1 || j==Board_col-1 || j==Board_col-2)
				{
					textField[i][j].setBackground(Color.GREEN);
				}
				textField[i][j].setColumns(10);
				panel.add(textField[i][j]);
				textField[i][j].setCaretPosition(SwingConstants.CENTER);
				textField[i][j].setHorizontalAlignment(SwingConstants.CENTER);
				textField[i][j].setForeground(Color.BLACK);
				//textField[i][j].setText("@");
				//textField[i][j].set
				textField[i][j].setBorder(null);
				
			}
		}
		txtLife.setBorder(null);
		
	
	}

	
	public void SetScreenClockMalos(String toPrint)
	{
		txtNextMonsterIn.setText(toPrint);
	}
	public void SetScreenClockGift(String toPrint,int type)
	{
		if(type==0) // digital clock
		{
			txtNextGiftIn.setVisible(true);
			progressBar.setVisible(false);
			txtNextGiftIn.setText(toPrint);
		}
		else  // grafic Clock 
		{
			txtNextGiftIn.setVisible(false);
			progressBar.setVisible(true);
			progressBar.setValue(Integer.parseInt(toPrint));
		}
		
	}
	
	
	public void SetScreenLife(int life)
	{
		txtLife.setText("Life     X      "+life);
	}
	public void SetScreenProgrees(int progrees)
	{
		txtProgress.setText("Progress: "+ progrees + "%");
	}
	public void SetScreenScore(int score)
	{
		txtScore.setText("Score: "+score);
	}
	public void SetScreenLevel(int level)
	{
		txtLevel.setText("Level: "+level );
	}
	
	public String GetValue(int i,int j)
	{
		return textField[i][j].getText();
	}
	public void SetValue(int i,int j,String value)
	{
		textField[i][j].setText(value);
		textField[i][j].setFont(new Font("Arial", Font.BOLD, 13));
	}
	public Color GetColorBackg(int i,int j)
	{
		return textField[i][j].getBackground();
	}
	public void SetColorBackg(int i,int j,Color color)
	{
		textField[i][j].setBackground(color);
	}
	public Color GetColorForg(int i,int j)
	{
		return textField[i][j].getForeground();
	}
	public void SetColorForg(int i,int j,Color color)
	{
		textField[i][j].setForeground(color);
	}



}
